package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Xiao
 * @date 2021/10/28
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdminCommentVO implements Serializable {
    private String id; //评论id
    private String nickname; //评论人昵称
    private Long userId;    //评论人id

    private String content; //评论
    private String createDate; //评论时间

    public static AdminCommentVO init(UserInfo userInfo, Comment comment) {
        AdminCommentVO commentVO = new AdminCommentVO();
        BeanUtils.copyProperties(userInfo, commentVO);
        BeanUtils.copyProperties(comment, commentVO);
        Date date = new Date(comment.getCreated());
        commentVO.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        commentVO.setId(comment.getId().toHexString());
        return commentVO;
    }
}
